﻿Public Class DRUGMAKER
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGMAKER_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASDRGMAKER()

        DesignForm(Me)
        DesignGrid(MASDRGMAKERGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASDRGMAKER()
        Dim objSelectDataMASDRGMAKER As New masdrgmaker
        Dim MASDRGMAKER As DataTable
        MASDRGMAKER = connect.GetTable(objSelectDataMASDRGMAKER.selectMasdrgmaker_)
        MASDRGMAKERGrid.PrimaryGrid.DataSource = MASDRGMAKER
    End Sub

    Private Sub MASDRGMAKERGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASDRGMAKERGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผู้ผลิตยา").Value() IsNot DBNull.Value Then
            DRGMIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผู้ผลิตยา").Value()
        Else
            DRGMIDTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อผู้ผลิตยา").Value() IsNot DBNull.Value Then
            MAKERNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อผู้ผลิตยา").Value()
        Else
            MAKERNAMETxt.Text = ""
        End If

        Try
            makerAddrTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ที่อยู่").Value()
        Catch ex As Exception
            makerAddrTxt.Clear()
        End Try

        Try
            makerTelTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("โทรศัพท์").Value()
        Catch ex As Exception
            makerTelTxt.Clear()
        End Try

        Try
            makerEmailTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("E-mail").Value()
        Catch ex As Exception
            makerEmailTxt.Clear()
        End Try

        Try
            remarkTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("หมายเหตุ").Value()
        Catch ex As Exception
            remarkTxt.Clear()
        End Try

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masdrgmakerStatusChk.Checked = True
        Else
            masdrgmakerStatusChk.Checked = False
        End If

        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masdrgmaker SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `drgmid` = '" & DRGMIDTxt.Text & "' ;"

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMasdrgmaker.Enabled = False
    End Sub

    Private Sub addMasdrgmaker_Click(sender As Object, e As EventArgs) Handles addMasdrgmaker.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If MAKERNAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masdrgmaker
                    objInsertData.MAKERNAME_ = MAKERNAMETxt.Text
                    objInsertData.MAKERADDR_ = makerAddrTxt.Text
                    objInsertData.MAKERTEL_ = makerTelTxt.Text
                    objInsertData.MAKEREMAIL_ = makerEmailTxt.Text
                    objInsertData.REMARK_ = remarkTxt.Text
                    objInsertData.STATUS_ = masdrgmakerStatusChk.Checked
                    objInsertData.insertMasdrgmakerData()

                    SelectDatagridMASDRGMAKER()

                    DRGMIDTxt.Text = ""
                    MAKERNAMETxt.Text = ""
                    masdrgmakerStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasdrgmaker_Click(sender As Object, e As EventArgs) Handles editMasdrgmaker.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If DRGMIDTxt.Text.ToString.Length > 0 And MAKERNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลผู้ผลิตยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masdrgmaker
                        objEditData.DRGMID_ = DRGMIDTxt.Text
                        objEditData.MAKERNAME_ = MAKERNAMETxt.Text
                        objEditData.MAKERADDR_ = makerAddrTxt.Text
                        objEditData.MAKERTEL_ = makerTelTxt.Text
                        objEditData.MAKEREMAIL_ = makerEmailTxt.Text
                        objEditData.REMARK_ = remarkTxt.Text
                        objEditData.STATUS_ = masdrgmakerStatusChk.Checked
                        objEditData.editMasdrgmakerData()

                        SelectDatagridMASDRGMAKER()

                        DRGMIDTxt.Text = ""
                        MAKERNAMETxt.Text = ""
                        masdrgmakerStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
                addMasdrgmaker.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrgmaker")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrgmaker")
        nextform.ShowDialog()
    End Sub
End Class